<?php
import('mydb.class.php');
import('basemodel.class.php');
class ModelUser extends BaseModel{
	var $uuid = null;
	public function __construct($uuid){
		parent::__construct();
		$this->uuid = $uuid;
	}

	public function updateLoginTime(){
		$date = date('Y-m-d H:i:s');
		$sql = "update  ps_user set last_login ='$date' where uuid = '$this->uuid'";
		$db = parent::getMyDB();
		$ret=$db->exec($sql);
		return isset($ret)?true:false;
	}
	
	public function addNewUser(){
		$date = date('Y-m-d H:i:s');
		$sql = "insert into ps_user(uuid,last_login) values ('$this->uuid','$date')";
		$db = parent::getMyDB();
		$ret=$db->exec($sql);
		return isset($ret)?true:false;
	}
	
	public function isUUIDExist(){
		$db = parent::getMyDB();
		$sql = "select uuid from ps_user where uuid = '$this->uuid'";
		$uuid = $db->queryOneValue($sql);
		return isset($uuid) && strlen($uuid) != 0;
	}

	public static function createTable(){
		$db = MyDB::getInstance();
		$sql_user = 'CREATE TABLE IF NOT EXISTS `ps_user` (
		`uuid` char(255) NOT NULL,
		`last_login` datetime DEFAULT NULL,
		PRIMARY KEY (`uuid`)
		) ENGINE=InnoDB DEFAULT CHARSET=latin1;';
		$db->exec($sql_user);
	}

	public static  function dropTable(){
		parent::dropTableByName('ps_user');
	}

}